<?php

namespace app\common\library;

use app\common\model\UserAdvise;
use app\common\library\YuUtil;

use think\db;

class YuAdvise
{
    const VERSION = '6.0.5';

    protected $errorString = '';

    public static $instance ;

    /**
     * @title 单例调用
     * @description 单例调用
     * @author Admin ldy
     * @time 2018/9/25  12:22
     */
    public static function getInstance(){
        if (YuAdvise::$instance == null){
            YuAdvise::$instance = new \app\common\library\YuAdvise;
            return YuAdvise::$instance;
        }else{
            return YuAdvise::$instance;
        }
    }

    public function __construct(){
        //初始化
    }

    public function setErrorString($msg){
        $this->errorString = $msg;
    }

    public function getErrorString(){
        return $this->errorString;
    }

    /**
     * @title 添加一条用户的意见与建议
     * @description 添加一条用户的意见与建议
     * <br>uid 用户id(如果是游客，就填写用户的唯一标志号，由前端生成，32位？)
     * <br>channel 反馈的渠道
     * <br>msg 用户的意见与建议
     * <br>status 回复的状态(1是后台未读，2是是后台已读但未回复，3是是后台回复但用户未读，4是用户已读)
     * <br>user_uuid 未登录用户的唯一标识(如果不登录用户的意见，就必须填这个）
     * <br>helpful_status 是否有帮助（1是有帮助的，2是没有帮助的，3是不知道是否有帮助，4是其他）
     * @author Admin ldy
     * @param name:$uid  type:string require:1 default:1 desc:
     * @param name:$options  type:string require:1 default:1 desc:<br>channel msg status user_uuid helpful_status
     * @time 2018/10/15  14:21
     * @return ReFail|ReSuccess
     */
    public static function addAdvise($uid,$options){
        $adviseObj = new UserAdvise;
        $adviseObj->user_id = $uid;
        $adviseObj->channel =YuUtil::getStringByKey('channel',$options);
        $adviseObj->msg =YuUtil::getStringByKey('msg',$options);
        $adviseObj->status =YuUtil::getStringByKey('status',$options);
        $adviseObj->user_uuid =YuUtil::getStringByKey('user_uuid',$options);
        $adviseObj->helpful_status =YuUtil::getStringByKey('helpful_status',$options);
        $re = $adviseObj->save();
        if ($re){
            return new ReSuccess('数据处理成功！',$adviseObj);
        }else{
            return new ReFail(ErrorType::ACTION_FAILED);
        }
    }





}
